package transporte.server.seguridad.aspect;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

@Component
public class VerificarPrivsInterceptor extends HandlerInterceptorAdapter {

	private static ThreadLocal<HttpSession> userSession = new ThreadLocal<HttpSession>();
	
	@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		userSession.set(request.getSession());
		return true;
    }

	@Override
    public void afterCompletion(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
	    userSession.remove();
    }
	
	static HttpSession getSession() {
		return userSession.get();
	}
	
}

